Title: All Tags
---
<div class="row">
    <div class="8u 12u$(medium)">
        @Html.Partial("_PostList", Model.DocumentList(Keys.PageDocuments).OrderByDescending(x => x.Get<DateTime>(BlogKeys.Published)))

        <nav>
            @{
                string tag = Model.String(BlogKeys.Tag).ToLowerInvariant().Replace(' ', '-');
                tag = tag.StartsWith(".") ? tag.Substring(1) : tag;
            }
            <ul class="pager">
                @if(Model.Bool(Keys.HasPreviousPage))
                {
                    string previousPage = Model.Get<int>(Keys.CurrentPage) == 2
                        ? $"/tags/{tag}.html" : $"/tags/{tag}{Model.Get<int>(Keys.CurrentPage) - 1}";
                <li class="previous">            
                        <a href="@previousPage"><span aria-hidden="true">&larr;</span> Newer</a>
                </li>   
                }          
                @if(Model.Bool(Keys.HasNextPage))
                {
                        string nextPage = $"/tags/{tag}{Model.Get<int>(Keys.CurrentPage) + 1}";
                <li class="next">
                        <a href="@nextPage">Older <span aria-hidden="true">&rarr;</span></a>
                </li>
                }
            </ul>
        </nav>
    </div>
    
    <div class="4u 12u$(medium)">
        <ul class="icons">
            @foreach (IDocument tagDocument in Documents[Blog.Tags]
                .GroupBy(x => x.String(BlogKeys.Tag)).Select(x => x.Where(p => p.Get<int>(Keys.CurrentPage) == 1).First())
                .OrderByDescending(x => x.Get<int>(Keys.TotalItems)))
            {
                string tagName = tagDocument.String(BlogKeys.Tag);
                string postCount = tagDocument.String(Keys.TotalItems);
                <li>
                    @if(tagName == Model.String(BlogKeys.Tag))
                    {
                        <strong><a href="@(Context.GetLink(tagDocument)).html">@tagName (@postCount)</a></strong>
                    }
                    else
                    {
                        <a href="@(Context.GetLink(tagDocument)).html">@tagName (@postCount)</a>
                    }
                </li>
            }
        </ul>
    </div>
</div>